#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <mysql/mysql.h>

//MySQL variables
static char *sqlServer = "localhost"; /* server host (default=localhost) */
static char *sqlUser = "root"; /* username (default=login name) */
static char *sqlPassword = ""; /* password (default=none) */
static unsigned int sqlPort = 3306; /* port number (use built-in value) */
static char *sqlSocket = NULL; /* socket name (use built-in value) */
static char *sqlDb = "advanse"; /* database name (default=none) */
static unsigned int sqlFlags = 0; /* connection flags (none) */

//structures
typedef struct {
    int plannedTimeId;
	int planId;
	int planningTime;
	int designTime;
	int codeTime;
	int compileTime;
	int testTime;
	int postMortemTime;
	int totalTime;
} PlannedTime;

typedef struct {
    int planInfoId;
	int planId;
	int planLOCPerHour;
	int planTotalTime;
	float planPercentReused;
	float planPercentNewReused;
	float actualPercentReused;
	float actualPercentNewReused;
} PlanInfo;

typedef struct {
    int plannedLOCId;
    int planId;
    float planBaseLOC;
    float planDeletedLOC;
    float planModifiedLOC;
    float planAddedLOC;
    float planReusedLOC;
    float planTotalNewAndChanged;
} PlannedLOC;

typedef struct {
    int actualLOCId;
    int planId;
    int actualBaseLOC;
    int actualDeletedLOC;
    int actualModifiedLOC;
    int actualAddedLOC;
    int actualReusedLOC;
    int actualTotalNewAndChanged;
} ActualLOC;

typedef struct {
    int planningInjected;
    int designInjected;
    int codeInjected;
    int compileInjected;
    int testInjected;
    int totalDevelopmentInjected;
} DefectsInjected;

typedef struct {
    int planningRemoved;
    int designRemoved;
    int codeRemoved;
    int compileRemoved;
    int testRemoved;
    int totalDevelopmentRemoved;
    int afterDevelopmentInjected;
} DefectsRemoved;

typedef struct {
    int userProjectId;
    int pspId;
} Project;

//functions
void ppsSetPlannedTimeDB(Project project, PlannedTime plannedTime)
{
    MYSQL *conn;    
    conn = mysql_init(NULL);
    
    if(project.pspId != 1)
    {
        if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
        {        
            char query[1000];
            sprintf(query, "INSERT INTO plannedtime (plan_id,planningTime,designTime,codeTime,compileTime,testTime,postMortemTime) VALUES(%d,%d,%d,%d,%d,%d,%d)",
                plannedTime.planId,
                plannedTime.planningTime,
                plannedTime.designTime,
                plannedTime.codeTime,
                plannedTime.compileTime,
                plannedTime.testTime,
                plannedTime.postMortemTime);
            mysql_query(conn, query);
        }
        else
        {
            printf("DATABASE CONNECTION ERROR!");
        }
    }
    else
    {
        if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
        {        
            char query[1000];
            sprintf(query, "INSERT INTO plannedtime (plan_id,totalTime) VALUES(%d,%d)",
                plannedTime.planId,
                plannedTime.totalTime);
            mysql_query(conn, query);
        }
        else
        {
            printf("DATABASE CONNECTION ERROR!");
        }
    }
    
    mysql_close(conn);
}

int ppsPlannedTimeCheck(PlannedTime plannedTime)
{
    MYSQL *conn;
    MYSQL_RES *result;
    conn = mysql_init(NULL);
    
    int returnVal = 0;
    
    if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
    {  
        char check[1000];
        sprintf(check, "SELECT * FROM plannedtime WHERE plan_id = %d", plannedTime.planId);
        mysql_query(conn, check);
        result = mysql_store_result(conn);
        
        if(mysql_num_rows(result)>=1)
        {
            returnVal = 1;
        }
        else
        {
            returnVal = 0;
        }
    }
    else
    {
        printf("DATABASE CONNECTION ERROR!");
    }
    mysql_close(conn);
    
    return returnVal;
}

void ppsSetPlannedTime(Project project)
{
    PlannedTime plannedTime;
    int totalTime;
    
    plannedTime.planId = ppsGetPlanIDFromProject(project);
    
    if(ppsPlannedTimeCheck(plannedTime) != 1)
    {
        printf("\nTime in Phase (min.)\n\n");
        
        if(project.pspId != 1)
        {
            printf("Planning: ");
            scanf("%d", &plannedTime.planningTime);
            
            printf("Design: ");
            scanf("%d", &plannedTime.designTime);
            
            printf("Code: ");
            scanf("%d", &plannedTime.codeTime);
            
            printf("Compile: ");
            scanf("%d", &plannedTime.compileTime);
            
            printf("Test: ");
            scanf("%d", &plannedTime.testTime);
            
            printf("Postmortem: ");
            scanf("%d", &plannedTime.postMortemTime);
            
            ppsSetPlannedTimeDB(project,plannedTime);
            
            totalTime = 
                plannedTime.planningTime + 
                plannedTime.designTime + 
                plannedTime.codeTime + 
                plannedTime.compileTime + 
                plannedTime.testTime + 
                plannedTime.postMortemTime;
        }
        else
        {
            printf("Total: ");
            scanf("%d", &plannedTime.totalTime);
            
            ppsSetPlannedTimeDB(project,plannedTime);
        }
    }
    else
    {
        printf("You've already filled this up.\n");
    }
}

PlannedTime ppsGetPlannedTime(Project project)
{
    MYSQL *conn;
    MYSQL_RES *result;
    MYSQL_ROW row;
    MYSQL_FIELD *field;
    conn = mysql_init(NULL);
    int num_fields,i;
    PlannedTime plannedTime;
    
    if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
    {  
        char check[1000];
        sprintf(check, "SELECT * FROM plannedtime WHERE plan_id = %d", ppsGetPlanIDFromProject(project));
        mysql_query(conn, check);
        result = mysql_store_result(conn);
        
        num_fields = mysql_num_fields(result);
        while ((row = mysql_fetch_row(result)))
        {
            for(i = 0; i < num_fields; i++)
            {
                char value[100];
                sprintf(value,"%s", row[i] ? row[i] : "NULL");
                
                switch(i)
                {
                    case 0: plannedTime.plannedTimeId = atoi(value);
                        break;
                    case 1: plannedTime.planId = atoi(value);
                        break;
                    case 2: plannedTime.planningTime = atoi(value);
                        break;
                    case 3: plannedTime.designTime = atoi(value);
                        break;
                    case 4: plannedTime.codeTime = atoi(value);
                        break;
                    case 5: plannedTime.compileTime = atoi(value);
                        break;
                    case 6: plannedTime.testTime = atoi(value);
                        break;
                    case 7: plannedTime.postMortemTime = atoi(value);
                        break;
                }
            }
        }
    }
    else
    {
        printf("DATABASE CONNECTION ERROR!");
    }
    
    mysql_free_result(result);
    mysql_close(conn);
    
    return plannedTime;
}

void ppsSetPlannedLOCDB(Project project, PlannedLOC plannedLOC)
{
    MYSQL *conn;    
    conn = mysql_init(NULL);
    
    if(project.pspId >= 4)
    {
        if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
        {
            char query[1000];
            sprintf(query, "INSERT INTO plannedloc (plan_id,planBaseLOC,planDeletedLOC,planModifiedLOC,planAddedLOC,planReusedLOC,planTotalNewAndChanged) VALUES (%d,%f,%f,%f,%f,%f,%f)",
                plannedLOC.planId,
                plannedLOC.planBaseLOC,
                plannedLOC.planDeletedLOC,
                plannedLOC.planModifiedLOC,
                plannedLOC.planAddedLOC,
                plannedLOC.planReusedLOC,
                plannedLOC.planTotalNewAndChanged);
            mysql_query(conn, query);
        }
        else
        {
            printf("DATABASE CONNECTION ERROR!");
        }
    }
    else
    {
        if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
        {
            char query[1000];
            sprintf(query, "INSERT INTO plannedloc (plan_id,planTotalNewAndChanged) VALUES (%d,%f)",
                plannedLOC.planId,
                plannedLOC.planTotalNewAndChanged);
            mysql_query(conn, query);
        }
        else
        {
            printf("DATABASE CONNECTION ERROR!");
        }
    }
    
    mysql_close(conn);
}

int ppsPlannedLOCCheck(PlannedLOC plannedLOC)
{
    MYSQL *conn;
    MYSQL_RES *result;
    conn = mysql_init(NULL);
    
    int returnVal = 0;
    
    if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
    {  
        char check[1000];
        sprintf(check, "SELECT * FROM plannedloc WHERE plan_id = %d", plannedLOC.planId);
        mysql_query(conn, check);
        result = mysql_store_result(conn);
        
        if(mysql_num_rows(result)>=1)
        {
            returnVal = 1;
        }
        else
        {
            returnVal = 0;
        }
    }
    else
    {
        printf("DATABASE CONNECTION ERROR!");
    }
    mysql_close(conn);
    
    return returnVal;
}

void ppsSetPlannedLOC(Project project)
{
    PlannedLOC plannedLOC;
    int totalNewAndChanged, totalLOC;
    
    plannedLOC.planId = ppsGetPlanIDFromProject(project);
    
    if(ppsPlannedLOCCheck(plannedLOC) != 1)
    {
        printf("\nProgram Size (LOC)\n\n");
        
        if(project.pspId >= 4)
        {
            printf("Base (B): ");
            scanf("%f", &plannedLOC.planBaseLOC);
            
            printf("  Deleted (D): ");
            scanf("%f", &plannedLOC.planDeletedLOC);
            
            printf("  Modified (M): ");
            scanf("%f", &plannedLOC.planModifiedLOC);
            
            printf("  Added (A): ");
            scanf("%f", &plannedLOC.planAddedLOC);
            
            printf("  Reused (R): ");
            scanf("%f", &plannedLOC.planReusedLOC);
    
            printf("Total New and Changed (N): "); // should actually be retrieved from Size Estimating Template
            scanf("%f", &plannedLOC.planTotalNewAndChanged);
            
            ppsSetPlannedLOCDB(project,plannedLOC);
            
            printf("Total LOC (T): "); // T = N+B-M-D+R
            scanf("%f", &totalLOC);
            
            printf("Total New Reused: "); // ????
            scanf("%f", &totalNewAndChanged);
        }   
        else
        {
            printf("Total New and Changed (N): ");
            scanf("%f", &plannedLOC.planTotalNewAndChanged);
            
            ppsSetPlannedLOCDB(project,plannedLOC);
        }
    }
    else
    {
        printf("You've already filled this up.\n");
    }
}

PlannedLOC ppsGetPlannedLOC(Project project)
{
    MYSQL *conn;
    MYSQL_RES *result;
    MYSQL_ROW row;
    MYSQL_FIELD *field;
    conn = mysql_init(NULL);
    int num_fields,i;
    PlannedLOC plannedLOC;
    
    if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
    {  
        char check[1000];
        sprintf(check, "SELECT * FROM plannedloc WHERE plan_id = %d", ppsGetPlanIDFromProject(project));
        mysql_query(conn, check);
        result = mysql_store_result(conn);
        
        num_fields = mysql_num_fields(result);
        while ((row = mysql_fetch_row(result)))
        {
            for(i = 0; i < num_fields; i++)
            {
                char value[100];
                sprintf(value,"%s", row[i] ? row[i] : "NULL");
                
                switch(i)
                {
                    case 0: plannedLOC.plannedLOCId = atoi(value);
                        break;
                    case 1: plannedLOC.planId = atoi(value);
                        break;
                    case 2: plannedLOC.planBaseLOC = atof(value);
                        break;
                    case 3: plannedLOC.planDeletedLOC= atof(value);
                        break;
                    case 4: plannedLOC.planModifiedLOC = atof(value);
                        break;
                    case 5: plannedLOC.planAddedLOC= atof(value);
                        break;
                    case 6: plannedLOC.planReusedLOC = atof(value);
                        break;
                    case 7: plannedLOC.planTotalNewAndChanged = atof(value);
                        break;
                }
            }
        }
    }
    else
    {
        printf("DATABASE CONNECTION ERROR!");
    }
    
    mysql_free_result(result);
    mysql_close(conn);
    
    return plannedLOC;
}

void ppsSetActualLOCDB(Project project, ActualLOC actualLOC)
{
    MYSQL *conn;    
    conn = mysql_init(NULL);
    
    if(project.pspId >= 2)
    {
        if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
        {
            char query[1000];
            sprintf(query, "INSERT INTO actualloc (plan_id,actualBaseLOC,actualDeletedLOC,actualModifiedLOC,actualAddedLOC,actualReusedLOC,actualTotalNewAndChanged) VALUES (%d,%d,%d,%d,%d,%d,%d)",
                actualLOC.planId,
                actualLOC.actualBaseLOC,
                actualLOC.actualDeletedLOC,
                actualLOC.actualModifiedLOC,
                actualLOC.actualAddedLOC,
                actualLOC.actualReusedLOC,
                actualLOC.actualTotalNewAndChanged);
            mysql_query(conn, query);
        }
        else
        {
            printf("DATABASE CONNECTION ERROR!");
        }
    }
    else
    {

        if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
        {
            char query[1000];
            sprintf(query, "INSERT INTO plannedloc (plan_id) VALUES (%d)",
                actualLOC.planId);
            mysql_query(conn, query);
        }
        else
        {
            printf("DATABASE CONNECTION ERROR!");
        }
    }
    
    mysql_close(conn);
}

int ppsSetActualLOCCheck(ActualLOC actualLOC)
{
    MYSQL *conn;
    MYSQL_RES *result;
    conn = mysql_init(NULL);
    
    int returnVal = 0;
    
    if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
    {  
        char check[1000];
        sprintf(check, "SELECT * FROM actualloc WHERE plan_id = %d", actualLOC.planId);
        mysql_query(conn, check);
        result = mysql_store_result(conn);
        
        if(mysql_num_rows(result)>=1)
        {
            returnVal = 1;
        }
        else
        {
            returnVal = 0;
        }
    }
    else
    {
        printf("DATABASE CONNECTION ERROR!");
    }
    mysql_close(conn);
    
    return returnVal;
}

void ppsSetActualLOC(Project project)
{
    ActualLOC actualLOC;
    int totalNewAndChanged, totalLOC;
    
    actualLOC.planId = ppsGetPlanIDFromProject(project);
    
    printf("\nProgram Size (LOC)\n\n");
    
    if(ppsSetActualLOCCheck(actualLOC) != 1)
    {        
        if(project.pspId >= 2)
        {
            printf("Base (B): ");
            scanf("%d", &actualLOC.actualBaseLOC);
            
            printf("  Deleted (D): ");
            scanf("%d", &actualLOC.actualDeletedLOC);
            
            printf("  Modified (M): ");
            scanf("%d", &actualLOC.actualModifiedLOC);
            
            printf("  Added (A): ");
            scanf("%d", &actualLOC.actualAddedLOC);
            
            printf("  Reused (R): ");
            scanf("%d", &actualLOC.actualReusedLOC);
    
            printf("Total New and Changed (N): "); // should actually be retrieved from Size Estimating Template
            scanf("%d", &actualLOC.actualTotalNewAndChanged);
            
            ppsSetActualLOCDB(project,actualLOC);
            
            printf("Total LOC (T): "); // T = N+B-M-D+R
            scanf("%f", &totalLOC);
            
            printf("Total New Reused: "); // ????
            scanf("%f", &totalNewAndChanged);
        }   
        else
        {
            /*
            printf("Total New and Changed (N): ");
            scanf("%f", &actualLOC.planTotalNewAndChanged);
            
            ppsSetPlannedLOCDB(project,plannedLOC);
            */
        }
    }
    else
    {
        printf("You've already filled this up.\n");
    }
}

ActualLOC ppsGetActualLOC(Project project)
{
    MYSQL *conn;
    MYSQL_RES *result;
    MYSQL_ROW row;
    MYSQL_FIELD *field;
    conn = mysql_init(NULL);
    int num_fields,i;
    
    ActualLOC actualLOC;
    
    actualLOC.actualBaseLOC = 0;
    actualLOC.actualDeletedLOC = 0;
    actualLOC.actualModifiedLOC = 0;
    actualLOC.actualAddedLOC = 0;
    actualLOC.actualReusedLOC = 0;
    actualLOC.actualTotalNewAndChanged = 0;
    
    if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
    {  
        char check[1000];
        sprintf(check, "SELECT * FROM actualloc WHERE plan_id = %d", ppsGetPlanIDFromProject(project));
        mysql_query(conn, check);
        result = mysql_store_result(conn);
        
        num_fields = mysql_num_fields(result);
        while ((row = mysql_fetch_row(result)))
        {
            for(i = 0; i < num_fields; i++)
            {
                char value[100];
                sprintf(value,"%s", row[i] ? row[i] : "NULL");
                
                switch(i)
                {
                    case 0: actualLOC.actualLOCId = atoi(value);
                        break;
                    case 1: actualLOC.planId = atoi(value);
                        break;
                    case 2: actualLOC.actualBaseLOC = atoi(value);
                        break;
                    case 3: actualLOC.actualDeletedLOC= atoi(value);
                        break;
                    case 4: actualLOC.actualModifiedLOC = atoi(value);
                        break;
                    case 5: actualLOC.actualAddedLOC= atoi(value);
                        break;
                    case 6: actualLOC.actualReusedLOC = atoi(value);
                        break;
                    case 7: actualLOC.actualTotalNewAndChanged = atoi(value);
                        break;
                }
            }
        }
    }
    else
    {
        printf("DATABASE CONNECTION ERROR!");
    }
    
    mysql_free_result(result);
    mysql_close(conn);
    
    return actualLOC;
}

PlannedTime ppsGetActualTime(Project project)
{
    MYSQL *conn;
    MYSQL_RES *result;
    MYSQL_ROW row;
    MYSQL_FIELD *field;
    conn = mysql_init(NULL);
    int num_fields,i;
    
    PlannedTime actualTime;
    long start, end, delta;
    int counter;
    
    if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
    {
        
        for(counter=1; counter<=6; counter++)
        {
            //Traverse phases
            char check[1000];
            sprintf(check, "SELECT * FROM timelog WHERE user_project_id = %d AND phase_id = %d", project.userProjectId, counter);
            
            if(mysql_query(conn, check)==0)
            {
                result = mysql_store_result(conn);
                num_fields = mysql_num_fields(result);
                while ((row = mysql_fetch_row(result)))
                {
                    for(i = 0; i < num_fields; i++)
                    {
                        char value[100];
                        sprintf(value,"%s", row[i] ? row[i] : "NULL");
                        
                        switch(i)
                        {
                            case 3: start = atoi(value);
                                break;
                            case 4: end = atoi(value);
                                break;
                        }
                    }
                }
                
                delta = end - start; // convert this to minutes
                
                switch(counter)
                {
                    case 1: actualTime.planningTime = delta;
                        break;
                    case 2: actualTime.designTime = delta;
                        break;
                    case 3: actualTime.codeTime = delta;
                        break;
                    case 4: actualTime.compileTime = delta;
                        break;
                    case 5: actualTime.testTime = delta;
                        break;
                    case 6: actualTime.postMortemTime = delta;
                        break;
                }
            }
            //end
        }
        
    }
    else
    {
        printf("DATABASE CONNECTION ERROR!");
    }
    
    mysql_free_result(result);
    mysql_close(conn);
    
    return actualTime;
}

DefectsInjected ppsGetDefectsInjected(Project project)
{
    DefectsInjected injected;
    /* retrieve from DB? */
    return injected;    
}

DefectsRemoved ppsGetDefectsRemoved(Project project)
{
    DefectsRemoved removed;
    /* retrieve from DB? */
    return removed;    
}

float ppsTotalPlannedLOC(PlannedLOC plannedLOC)
{
    float t;
    t = plannedLOC.planTotalNewAndChanged +
        plannedLOC.planBaseLOC -
        plannedLOC.planModifiedLOC -
        plannedLOC.planDeletedLOC +
        plannedLOC.planReusedLOC;
        
    return t;
}

int ppsTotalActualLOC(ActualLOC actualLOC)
{
    int t;
    t = actualLOC.actualTotalNewAndChanged +
        actualLOC.actualBaseLOC -
        actualLOC.actualModifiedLOC -
        actualLOC.actualDeletedLOC +
        actualLOC.actualReusedLOC;
        
    return t;
}

void ppsDisplayProjectPlanSummary(Project project)
{
    PlannedTime plannedTime;
    plannedTime = ppsGetPlannedTime(project);
    
    PlannedLOC plannedLOC;
    plannedLOC = ppsGetPlannedLOC(project);
    
    ActualLOC actualLOC;
    actualLOC = ppsGetActualLOC(project);
    
    printf("\nProgram Size (LOC)\tPlan\tActual\tTo Date\n");
    printf("========================================================\n");
    printf("Base\t\t\t%.2f\t%d\t100\n", plannedLOC.planBaseLOC, actualLOC.actualBaseLOC);
    printf("  Deleted\t\t%.2f\t%d\t100\n", plannedLOC.planDeletedLOC, actualLOC.actualDeletedLOC);
    printf("  Modified\t\t%.2f\t%d\t100\n", plannedLOC.planModifiedLOC, actualLOC.actualModifiedLOC);
    printf("  Added\t\t\t%.2f\t%d\t100\n", plannedLOC.planAddedLOC, actualLOC.actualAddedLOC);
    printf("  Reused\t\t%.2f\t%d\t100\n", plannedLOC.planReusedLOC, actualLOC.actualReusedLOC);
    printf("Total New and Changed\t%.2f\t%d\t100\n", plannedLOC.planTotalNewAndChanged, actualLOC.actualTotalNewAndChanged);
    printf("Total LOC\t\t%.2f\t%d\t100\n", ppsTotalPlannedLOC(plannedLOC), ppsTotalActualLOC(actualLOC));
    printf("Total New Reused\t0\t0\t100\n");
        
    printf("\nTime in Phase (min.)\tPlan\tActual\tTo Date\tTo Date%%\n");
    printf("========================================================\n");
    printf("Planning\t\t%d\t100\t100\t100\n", plannedTime.planningTime);
    printf("Design\t\t\t%d\t100\t100\t100\n", plannedTime.designTime);
    printf("Code\t\t\t%d\t100\t100\t100\n", plannedTime.codeTime);
    printf("Compile\t\t\t%d\t100\t100\t100\n", plannedTime.compileTime);
    printf("Test\t\t\t%d\t100\t100\t100\n", plannedTime.testTime);
    printf("Postmortem\t\t%d\t100\t100\t100\n", plannedTime.postMortemTime);
    printf("  Total\t\t\t100");
}

int ppsGetPlanIDFromProject(Project project)
{
    MYSQL *conn;
    MYSQL_RES *result;
    MYSQL_ROW row;
    MYSQL_FIELD *field;
    conn = mysql_init(NULL);
    int num_fields,i;
    
    int id;
    
    if(mysql_real_connect(conn, sqlServer, sqlUser, sqlPassword, sqlDb, 0, NULL, 0) != NULL)
    {  
        char check[1000];
        sprintf(check, "SELECT * FROM plansummary WHERE user_project_id = %d", project.userProjectId);
        mysql_query(conn, check);
        result = mysql_store_result(conn);
        
        num_fields = mysql_num_fields(result);
        while ((row = mysql_fetch_row(result)))
        {
            for(i = 0; i < num_fields; i++)
            {
                char value[100];
                sprintf(value,"%s", row[i] ? row[i] : "NULL");
                
                switch(i)
                {
                    case 0: id = atoi(value);
                        break;
                    case 1:
                        break;
                }
            }
        }
    }
    else
    {
        printf("DATABASE CONNECTION ERROR!");
    }
    
    mysql_free_result(result);
    mysql_close(conn);
    
    return id;
}

int main(int argc, char **argv)
{
    Project project;
    int select;
    
    project.userProjectId = 1;
    project.pspId = 4;
    
    ppsGetActualTime(project);
    
    printf("[1] Plan\n");
    printf("[2] Actual\n");
    printf("[3] Display Project Plan Summary\n\n");
    printf("Select: ");
    scanf("%d", &select);
    
    switch(select)
    {
        case 1: ppsSetPlannedLOC(project);  
                ppsSetPlannedTime(project);                
            break;
        case 2: ppsSetActualLOC(project);
                ppsGetActualTime(project);
            break;
        case 3: ppsDisplayProjectPlanSummary(project);
            break;
    }
    
    
    getch();
    return 0;
}
